package com.example.yls.demoa;

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button load;
    private Button play1;
    private Button play2;
    private Button play3;
    private Button play4;
    private Button play5;
    private int[]soundIDArr=new int[5];
    private SoundPool soundPool;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findView();
          load.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                 soundPool=new SoundPool(10, AudioManager.STREAM_MUSIC,
                         0);
                 soundIDArr[0]=soundPool.load(MainActivity.this,R.raw.shangfeng,
                         1);
                  soundIDArr[1]=soundPool.load(MainActivity.this,R.raw.ding,
                          1);
                  soundIDArr[2]=soundPool.load(MainActivity.this,R.raw.enter,
                          1);
                  soundIDArr[3]=soundPool.load(MainActivity.this,R.raw.notify,
                          1);
                  soundIDArr[4]=soundPool.load(MainActivity.this,R.raw.ringout,
                          1);

              }
          });

        play1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIDArr[0],1,1,
                        1,0,1);

            }
        });
        play2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIDArr[1],1,1,
                        1,0,1);

            }
        });
        play3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIDArr[2],1,1,
                        1,0,1);
            }
        });
        play4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIDArr[3],1,1,
                        1,0,1);
            }
        });
        play5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIDArr[4],1,1,
                        1,0,1);
            }
        });


    }

    private void findView() {
        load=findViewById(R.id.btn_load);
        play1=findViewById(R.id.btn_play1);
        play2=findViewById(R.id.btn_play2);
        play3=findViewById(R.id.btn_play3);
        play4=findViewById(R.id.btn_play4);
        play5=findViewById(R.id.btn_play5);

    }
}
